package edu.fiu.cis.personalize.server.berkDB.serializers;

import com.sleepycat.bind.tuple.TupleInput;
import com.sleepycat.bind.tuple.TupleOutput;

import edu.fiu.cis.personalize.server.graph.Document;
import edu.fiu.cis.personalize.server.graph.store.CountingConcMap;
import edu.fiu.cis.personalize.server.graph.store.NodeEdges;

public class DocumentSerializer extends NodeSerializer<Document> {

	CountingConcMapSerializer ser = new CountingConcMapSerializer();

	@Override
	public void objectToEntry(Document node, TupleOutput to) {
		super.objectToEntry(node, to);
		to.writeString(node.getTitle());
		to.writeString(node.getContent());
		// write the rest of the data
		ser.objectToEntry(node.getClickedByUser(), to);
		ser.objectToEntry(node.getDisplayedAfterQuery(), to);
		ser.objectToEntry(node.getClickedAfterQuery(), to);
	}

	@Override
	protected Document process(TupleInput ti, int id, String url,
			NodeEdges nodeEdges, double rank) {
		String title = ti.readString();
		String content = ti.readString();
		CountingConcMap cu = (CountingConcMap) ser.entryToObject(ti);
		CountingConcMap daq = (CountingConcMap) ser.entryToObject(ti);
		CountingConcMap caq = (CountingConcMap) ser.entryToObject(ti);
		return Document.create(id, url, nodeEdges, rank, title, content, cu,
				daq, caq);
	}

}
